package com.jincheng.web.controller.system;

import com.jincheng.common.core.controller.BaseController;
import com.jincheng.common.core.domain.AjaxResult;
import com.jincheng.common.core.page.TableDataInfo;
import com.jincheng.system.domain.UserTribe;
import com.jincheng.system.domain.dto.UserTribeDetailDTO;
import com.jincheng.system.domain.dto.UserTribeScreenDTO;
import com.jincheng.system.service.IUserTribeService;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户部落报名信息
 */
@RestController
@RequestMapping("/system/userTribe")
public class UserTribeController extends BaseController {

    private final IUserTribeService userTribeService;

    public UserTribeController(IUserTribeService userTribeService) {
        this.userTribeService = userTribeService;
    }


    @GetMapping("/list")
    public TableDataInfo list(@RequestBody UserTribe userTribe) {
        startPage();
        List<UserTribe> list = userTribeService.selectUserTribeList(userTribe);
        return getDataTable(list);
    }

    @GetMapping("/list/detail/tribe/{tribeId}")
    public TableDataInfo listDetail(@PathVariable("tribeId") Long tribeId,
                                    UserTribeScreenDTO userTribeScreenDTO) {
        userTribeScreenDTO.setTribeId(tribeId);
        startPage();
        List<UserTribeDetailDTO> list = userTribeService.selectUserTribeDetailList(userTribeScreenDTO);
        return getDataTable(list);
    }



    @GetMapping("/{userTribeId}")
    public AjaxResult getInfo(@PathVariable("userTribeId") Long userTribeId) {
        UserTribe userTribe = userTribeService.selectUserTribeById(userTribeId);
        return success(userTribe);
    }



    @PostMapping
    public AjaxResult add(@RequestBody UserTribe userTribe) {
        return toAjax(userTribeService.insertUserTribe(userTribe));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody UserTribe userTribe) {
        return toAjax(userTribeService.updateUserTribe(userTribe));
    }

    /**
     * 修改用户报名部落的审核状态
     */
    @PutMapping("/status")
    public AjaxResult changeStatus(@RequestBody UserTribeDetailDTO userTribeDetailDTO) {
        return toAjax(userTribeService.changeStatus(userTribeDetailDTO));
    }

    @DeleteMapping("/{userTribeIds}")
    public AjaxResult remove(@PathVariable Long[] userTribeIds) {
        return toAjax(userTribeService.deleteUserTribeByIds(userTribeIds));
    }
}
